import React, { Component } from 'react';

import Search from "../../components/todolist/Search"; //头部输入
import List from "../../components/todolist/List"; //列表
import "../../index.css";

class Todolist extends Component {

  state = { 
    list: [
      {
        name: "第一条记事本"
      },
      {
        name: "第二条记事本"
      },
      {
        name: "第三条记事本"
      }
    ]
   }

   todolist =(msg)=>{ //msg是子组件传过来的
    console.log(msg);
    let data = [...this.state.list]
    console.log(data);
    data.push(msg)
    this.setState({
      list: data
    })
   }


  render() { 
    return ( 
      <>
        <div className='todolist'>
          {/* 头部输入框 */}
          <Search todolist={this.todolist}></Search>
          {/* 列表 */}
          <List list={this.state.list}></List>
        </div>
      </>
     );
  }
}
 
export default Todolist;